/*
 * Copyright 2008 the original author Ang Gao.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * postagger.java 2008-12-15
 */
package ie.ucc.cs.anggao.finalproject.server.AI;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import opennlp.tools.lang.english.PosTagger;
import opennlp.tools.postag.POSDictionary;

/**
 * @author GaoAng
 * 
 */
public class postagger {

	private POSDictionary dic;
	private PosTagger tagger;

	public postagger() {
		try {
			dic = new POSDictionary("models/parser/tagdict", false);
			tagger = new PosTagger("models/parser/tag.bin.gz", dic);
		} catch (IOException e) {

			e.printStackTrace();
		}

	}

	public String POStagger(String s) {

		ArrayList toks = new ArrayList();
		
		StringTokenizer st = new StringTokenizer(s);
		
		while (st.hasMoreTokens())
			toks.add(st.nextToken());
		
		List tags = tagger.tag(toks);
		
		StringBuffer sb = new StringBuffer();
		
		for (int i = 0; i < tags.size(); i++) {
			if (tags.get(i).toString().startsWith("NN")){
				System.out.print(toks.get(i) + "/" + tags.get(i) + " ");
				sb.append(toks.get(i) + " ");
			}
				
		}



		String pos = sb.toString().trim();
		return pos;
	}

	public static void main(String[] args) {


	}
}
